package com.jmpt.fangbohui.helper;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jmpt.fangbohui.Constants;
import com.jmpt.fangbohui.MyApplication;
import com.jmpt.fangbohui.bean.BannerBean;
import com.jmpt.fangbohui.bean.PromoteBean;
import com.jmpt.fangbohui.bean.RecommendBean;
import com.jmpt.fangbohui.utils.DebugLog;

/**
 * 专门用于获取缓存数据
 * 
 * @author Victor
 * 
 */
public class HistoryHelper {

	public static List<BannerBean> getHistoryBannersData() throws Exception {
		try {
			return new Gson().fromJson(MyApplication.getSharedPreferences()
					.getString(Constants.SharedPreferences.HOME_BANNERS_DATA, ""),
					new TypeToken<List<BannerBean>>() {}.getType());
		} catch (Exception e) {
			DebugLog.e(e.getMessage());
			throw e;
		}
	}

	public static List<RecommendBean> getHistoryRecommendsData() throws Exception {
		try {
			return new Gson().fromJson(MyApplication.getSharedPreferences()
					.getString(Constants.SharedPreferences.HOME_RECOMMENDS_DATA, ""),
					new TypeToken<List<RecommendBean>>() {}.getType());
		} catch (Exception e) {
			DebugLog.e(e.getMessage());
			throw e;
		}
	}

	public static List<PromoteBean> getHistoryPromotesData() throws Exception {
		try {
			return new Gson().fromJson(MyApplication.getSharedPreferences()
					.getString(Constants.SharedPreferences.HOME_PROMOTES_DATA, ""),
					new TypeToken<List<PromoteBean>>() {}.getType());
		} catch (Exception e) {
			DebugLog.e(e.getMessage());
			throw e;
		}
	}

}
